package com.hgvip.util;

/**
 * @author arnold.zhu
 * @date 2018/3/26
 */
public interface DistributedLock {

    /***
     * 失效时间30000秒
     */
    long TIMEOUT_MILLIS = 30000;

    /***
     * 重试次数3次
     */
    int RETRY_TIMES = 3;

    /***
     * 每次执行失败后休眠500毫秒
     */
    long SLEEP_MILLIS = 500;

    boolean lock(String key);

    boolean lock(String key, int retryTimes);

    boolean lock(String key, int retryTimes, long sleepMillis);

    boolean lock(String key, long expire);

    boolean lock(String key, long expire, int retryTimes);

    /***
     * 加锁
     *
     * @param key 键
     * @param expire 有效时间
     * @param retryTimes 重试次数
     * @param sleepMillis  每次重试后的休眠时间
     * @return boolean
     */
    boolean lock(String key, long expire, int retryTimes, long sleepMillis);

    /***
     * 释放锁
     *
     * @param key 键
     * @return boolean
     */
    boolean releaseLock(String key);

}
